<#assign content>
<div class="right_col" role="main">
    <div class="">
        <div class="page-title">
            <div class="title_left">
                <h3>角色-功能设置</h3>
            </div>
        </div>
        <div class="clearfix"></div>
        <div class="row">
            <div class="col-md-12 col-sm-12 col-xs-12">
                <div class="col-md-12 col-sm-12 col-xs-12">
                    <div class="x_panel">
                        <div class="x_title">
                            <h2><small></small></h2>
                            <div class="clearfix"></div>
                        </div>
                        <div class="x_content">
                            <p class="text-muted font-13 m-b-30">
                            </p>
                            <select id="action-select" multiple="multiple">
                            </select>
                            <div class="ln_solid"></div>
                            <div class="form-group">
                                <div class="col-md-6 col-md-offset-5">
                                    <button id="save_roleaction" type="button" class="btn btn-success">保存</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</#assign>
<#include "../_inc/layout.ftl" />
<script>
    <#if actionList?exists>
        var action_select = $('#action-select');
        action_select.append('${actionList}');
        action_select.treeMultiselect({
            enableSelectAll: true,
            selectAllValue: 'multiselect-all',
            enableFiltering: false,
            sortable: true,
            selectAllText: '全选',
            unselectAllText: '取消全选',
            selectedClass: 'multiselect-selected'
        });
    </#if>
    //
    $('#save_roleaction').on('click', function () {
        var actionValue = $("#action-select").val();
        if(actionValue != null && $("#action-select").val().length > 0) {
            var actionArray = [];
            for ( var i = 0; i < actionValue.length; i++) {
                if(actionValue[i] != null){
                    actionArray.push(actionValue[i]);
                }
            }
            var param = {};
            param.id = '${id}';
            param.action = 'roleSetAction';
            param.actionValue = actionArray;
            $.ajax({
                type: 'POST',
                url: '/role_set_action.do',
                cache: false,                                   //禁用缓存
                data: param,                                    //传入组装的参数
                dataType: 'json',
                traditional: true,
                success: function (result) {
                    if(result.success) {
                        location.reload();                      // 刷新
                    }
                    else {
                        $.promptModal('${warning}', result.msg, result.logout);
                    }
                },
                error: function(XMLHttpRequest, textStatus, errorThrown) {
                    $.promptModal('${warning}', '${systemException}', false);
                }
            });
        }
        else {
            $.promptModal('${warning}', '请选择功能', false);
        }
    });
</script>